import { cloudService } from './index'
import { ILedgerRecord } from '@/types/ledger'

export const addLedgerApi = (ledger: ILedgerRecord): Promise<boolean> =>
  cloudService({
    url: '/home-api/ledger',
    method: 'post',
    data: ledger
  })

export const updateLedgerApi = (id: number, ledger: ILedgerRecord): Promise<boolean> =>
  cloudService({
    url: `/home-api/ledger/${id}`,
    method: 'put',
    data: ledger
  })

export const deleteLedgerApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/ledger/${id}`,
    method: 'delete'
  })

export const queryLedgerApi = (book: string): Promise<ILedgerRecord[]> =>
  cloudService({
    url: '/home-api/ledger',
    method: 'get',
    params: { book }
  })

export const queryLedgerBookApi = (): Promise<string[]> =>
  cloudService({
    url: '/home-api/ledger/book',
    method: 'get'
  })
